/* 
	PROG: dna
	LANG: C++
	ID: luiza1
*/

#include <stdio.h>

int m;
int f;
char male[22][25];
char female[22][25];
int count;

int main() {
	freopen("dna.in", "r", stdin);
	freopen("dna.out", "w", stdout);

	scanf("%d %d", &m, &f);

	for (int i=0; i<m; i++) {
		for (int j=0; j<25; j++)
			scanf(" %c", &male[i][j]);
	}
	
	for (int i=0; i<f; i++) {
		for (int j=0; j<25; j++)
			scanf(" %c", &female[i][j]);
	}

	for (int i=0; i<m; i++) {
		for (int j=0; j<f; j++) {
			count=0;

			for (int k=0; k<m; k++) {
				if (k==i) continue;
				int ln;

				for (ln=0; ln<25; ln++)
					if (male[k][ln]!=male[i][ln] && male[k][ln]!=female[j][ln])
						break;

				if (ln==25) count++;
			}

			for (int k=0; k<f; k++) {
				if (k==j) continue;
				int ln;

				for (ln=0; ln<25; ln++)
					if (female[k][ln]!=male[i][ln] && female[k][ln]!=female[j][ln])
						break;

				if (ln==25) count++;
			}

			printf("%d", count);

			if ((j+1)<f) printf(" ");
		}

		printf("\n");
	}

	return 0;
}
